package shg.book.util
{
	import flash.display.BitmapData;
	import flash.display.Sprite;
	
	import mx.controls.Image;
	
	import shg.book.size.BookData;

	public class Tools
	{
		public function Tools()
		{
		}
		public static function drawImage(_x1:int,_x2:int,_x3:int,_x4:int,
										 _y1:int,_y2:int,_y3:int,_y4:int,
										 positionX:int,positionY:int,bitmapData:BitmapData):Sprite{
			var x1:Number =-_x1,   y1:Number =-_y1,    z1:Number = 30,    t1:Number =1; 
			var x2:Number =_x2,    y2:Number =-_y2,    z2:Number =-30,    t2:Number = 1; 
			var x3:Number =_x3,    y3:Number =_y3,    z3:Number =-30,    t3:Number = 1; 
			var x4:Number =-_x4,   y4:Number =_y4,    z4:Number = 30,    t4:Number = 1; 
			
			var sprite:Sprite=new Sprite();
			sprite.x=positionX;
			sprite.y=positionY;
			
			var vertices:Vector.<Number> = new Vector.<Number>(); 
			vertices.push(x1*t1,y1*t1, x2*t2,y2*t2, x3*t3,y3*t3, x4*t4,y4*t4); 
			
			var indices:Vector.<int> =  new Vector.<int>(); 
			indices.push(0,1,3, 1,2,3); 
			
			var uvtData:Vector.<Number> = new Vector.<Number>(); 
			uvtData.push(0,0,t1, 1,0,t2, 1,1,t3, 0,1,t4); 
			//绘制一个图形
			sprite.graphics.beginBitmapFill(bitmapData);
			//修改上面的图形，把他变成一个任意形状的图形
			sprite.graphics.drawTriangles(vertices, indices, uvtData); 
			//将对象添加到指定的容易里面
			return sprite;
		}
		public static function drawSprite(_x1:int,_x2:int,_x3:int,_x4:int,
										 _y1:int,_y2:int,_y3:int,_y4:int,
										 positionX:int,positionY:int,sprite:Sprite):Sprite{
			var x1:Number =-_x1,   y1:Number =-_y1,    z1:Number = 30,    t1:Number =1; 
			var x2:Number =_x2,    y2:Number =-_y2,    z2:Number =-30,    t2:Number = 1; 
			var x3:Number =_x3,    y3:Number =_y3,    z3:Number =-30,    t3:Number = 1; 
			var x4:Number =-_x4,   y4:Number =_y4,    z4:Number = 30,    t4:Number = 1; 
			
			var sprite:Sprite=sprite;
			sprite.x=positionX;
			sprite.y=positionY;
			
			var vertices:Vector.<Number> = new Vector.<Number>(); 
			vertices.push(x1*t1,y1*t1, x2*t2,y2*t2, x3*t3,y3*t3, x4*t4,y4*t4); 
			
			var indices:Vector.<int> =  new Vector.<int>(); 
			indices.push(0,1,3, 1,2,3); 
			
			var uvtData:Vector.<Number> = new Vector.<Number>(); 
			uvtData.push(0,0,t1, 1,0,t2, 1,1,t3, 0,1,t4); 
			//修改上面的图形，把他变成一个任意形状的图形
			sprite.graphics.drawTriangles(vertices, indices, uvtData); 
			//将对象添加到指定的容易里面
			return sprite;
		}
		
	}
}